package com.app.couponsharelife.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.app.couponsharelife.R
import com.app.couponsharelife.data.bean.TaobaoGoodBean
import com.app.couponsharelife.ui.listener.OnClickListener
import kotlinx.android.synthetic.main.dialog_sousuo_goods.*

/**
 *Created by xct on 2019/1/22
 *Description:复制商品弹窗
 */
class SearchGoodsDialog(context: Context, themeResId: Int, private var taobaoGoodBean: TaobaoGoodBean, private val listener: OnClickListener) : Dialog(context, themeResId) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_sousuo_goods)
        initView()
    }

    private fun initView() {
        goodsdialog_imgclose.setOnClickListener { dismiss() }
        goodsdialog_name.text=taobaoGoodBean.title
        goodsdialog_tvprice.text="￥${taobaoGoodBean.final_price}"
        goodsdialog_tvcouponprice.text="${taobaoGoodBean.coupon_price}元券"
        goodsdialog_tvoldprice.text="￥${taobaoGoodBean.zk_final_price}"
        if (!taobaoGoodBean.has_coupon){
            goodsdialog_tvcouponprice.visibility=View.GONE
        }
        Glide.with(context)
                .load(taobaoGoodBean.pict_url)
                .apply(RequestOptions().error(R.drawable.ic_app_place_holder2))
                .into(goodsdialog_img)
        findViewById<TextView>(R.id.goodsdialog_butqx).setOnClickListener {
            //listener.click(0, "")
            dismiss()
        }
        findViewById<TextView>(R.id.goodsdialog_butqd).setOnClickListener {
            listener.click(1, "")
            dismiss()
        }
        window!!.setWindowAnimations(R.style.scale_in_alpha_out)
        setCanceledOnTouchOutside(true)

        //设置dialog没有边距
        window!!.decorView.setPadding(0, 0, 0, 0)
        val lp = window!!.attributes
        lp.width = WindowManager.LayoutParams.MATCH_PARENT
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT
        window!!.attributes = lp
    }
}